﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi001.Domain.Entity;

namespace WebApi001.Domain
{
    public class DbInitializeHelper
    {
        public static void Initilizer()
        {
            using(var db=new Admin4000DbContext())
            {
                var dbExist=db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {

                    var brand = new Brand
                    {
                        BrandName = "壹号爆辣王",
                        Description = "它是一瓶特别辣的辣椒，真的超级辣"
                    };

                    db.Brands.Add(brand);

                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                        {
                        new Product
                        {
                            ProductName="壹号辣椒 特辣",
                            ShortDesc="这是一个简单的简介",
                            FullDesc="这是一个详情",
                            BrandId=brand.Id
                        },new Product
                        {
                             ProductName="壹号辣椒 微辣",
                            ShortDesc="这是一个很难的简介",
                            FullDesc="这是一个很难很难详情",
                            BrandId=brand.Id
                        }
                        });
                    db.SaveChanges();

                }
                
            }
        }
    }
}
